import { createStore } from 'vuex'

export default createStore({
    state: {
        userMsg: {},
        token: '',
        id: '',
        Max: 6000,
    },
    mutations: {
        setMax(state, Max) {
            state.Max = Max;
        },
        initUsermsg(state, query) {
            state.userMsg = query
            localStorage.setItem('userMsg', JSON.stringify(query))
        },
        // 下线
        resetStore(state) {
            state.userMsg = {}
            state.token = ''
            state.id = ''
            localStorage.clear()
        },
        initStore(state) {
            state.token = localStorage.getItem('token')
            state.id = localStorage.getItem('id')
            state.userMsg = JSON.parse(localStorage.getItem('userMsg')) || {}
        },
        login(state, query) {
            localStorage.setItem('token', query.token)
            localStorage.setItem('id', query.id)
            state.token = query.token
            state.id = query.id
        },
        changeAvatar(state, query) {
            state.userMsg.photo = query
            localStorage.setItem('userMsg', JSON.stringify(state))
        }
    }
})